/**
 *  广告模块整合 20171023
 */
define(function(require,exports,module) {
    var myPub = require('./public');
    var htmlFontSize, intSize, stretchs, stretchLong;
    var resizeTimer = null;
    var lazLoading = new myPub.lazLoadingImg();

    var drawCouponUrl = '/m/o/coupon/1.0/drawCoupon';        // 领取优惠券接口

    // 页面尺寸修改111111
    $(window).on('resize',function() {
        if (resizeTimer) {
            clearTimeout(resizeTimer)
        }
        resizeTimer = setTimeout(function(){
            htmlFontSize = $('html').css('font-size');
            intSize = parseInt(htmlFontSize.split('p')[0]);
            stretchs = 174/26*intSize;
            stretchLong = intSize;
            adsInit.SetAdsRotate(stretchs);
            adsInit.SetAdsLongSwiper(stretchLong);
        }, 400);
    });

    // var BASE_URL = '';
    var adsInit = {
        time_CutTime: null,             // 倒计时计时器
        time_RunHouse: null,            // 头条计时器
        oSlideAdsScroll: [],            // 横排滚动广告
        oSlideAdsRotate: [],            // 旋转滚动广告
        oSlideAdsLongSwiper: [],        // 长形滚动广告
        oSlideAdsIconSwiper: [],        // icon滚动广告

        // 设置长条滚动广告
        SetAdsLongSwiper: function (stretch) {
            var _this = this;
            var oAdsLong_HScrollSwiper = $('.js_AdsLong_HScrollSwiper');
            if(stretch === undefined) {
                var _htmlFontSize = $('html').css('font-size');
                var _intSize = parseInt(_htmlFontSize.split('p')[0]);
                stretch = _intSize;
            }

            oAdsLong_HScrollSwiper.each(function (i) {
                if(_this.oSlideAdsLongSwiper[i] === undefined) {
                    AddSwiper(i, stretch);
                }
                else {
                    _this.oSlideAdsLongSwiper[i].destroy();
                    AddSwiper(i, stretch);
                }
            });

            function AddSwiper(i, stretch) {
                _this.oSlideAdsLongSwiper[i] = oAdsLong_HScrollSwiper.eq(i).swiper({
                    pagination: '.js_pagin',
                    loop: true,
                    loopAdditionalSlides: 1,
                    observer: true,
                    observeParents: true,
                    slidesOffsetBefore: 0,
                    autoplay: 3000,
                    autoplayDisableOnInteraction : false,
                    effect : 'slide',
                    // slidesPerView: 1.039,
                    centeredSlides: false,
                    /*coverflow: {
                        rotate: 0,
                        stretch: -stretch,
                        depth: 75,
                        modifier: 4,
                        slideShadows : false
                    },*/
                    onTouchEnd: function (swiper) {
                        var index = swiper.activeIndex;
                        var _swSlid = oAdsLong_HScrollSwiper.eq(i).find('.swiper-slide a');
                        var swiper_href = _swSlid.eq(index).attr('swiper_href');
                        if(typeof swiper_href != 'undefined') {
                            _swSlid.removeAttr('href').eq(index).attr('href', swiper_href)
                        }
                    }
                });
            }

        },

        // 设置旋转滚动广告
        SetAdsRotate:function (stretch) {
            var _this = this;
            var oHRotateBox = $('.js_HRotate');
            var oPagin = oHRotateBox.find('.js_pagin');

            if(stretch === undefined) {
                var _htmlFontSize = $('html').css('font-size');
                var _intSize = parseInt(_htmlFontSize.split('p')[0]);
                stretch = 174/26*_intSize;
            }

            oHRotateBox.each(function (i) {
                if(_this.oSlideAdsRotate[i] === undefined) {
                    AddSwiper(i, stretch);
                }
                else {
                    _this.oSlideAdsRotate[i].destroy();
                    AddSwiper(i, stretch);
                }
            });

            function AddSwiper(i, stretch) {
                _this.oSlideAdsRotate[i] = oHRotateBox.eq(i).swiper({
                    pagination: oPagin.eq(i),
                    loop: true,
                    loopAdditionalSlides: 1,
                    observer: true,
                    observeParents: true,
                    roundLengths: true,
                    followFinger:false,
                    autoplay: 3000,
                    autoplayDisableOnInteraction : false,
                    effect : 'coverflow',
                    slidesPerView: 2.14,
                    centeredSlides: true,
                    coverflow: {
                        rotate: 0,
                        stretch: stretch,
                        depth: 200,
                        modifier: 1,
                        slideShadows : false
                    },

                    onTouchEnd: function (swiper) {
                        var index = swiper.activeIndex;
                        var _swSlid = oHRotateBox.eq(i).find('.swiper-slide a');
                        var swiper_href = _swSlid.eq(index).attr('swiper_href');
                        if(typeof swiper_href != 'undefined'){
                            _swSlid.removeAttr('href').eq(index).attr('href', swiper_href)
                        }
                    }
                });
            }

        },

        // 设置滚动广告
        SetAdsLiScroll: function () {
            var _this = this;
            var oHScrollBox = $('.js_HScroll');
            oHScrollBox.each(function (i) {
                if(_this.oSlideAdsScroll[i] === undefined) {
                    _this.oSlideAdsScroll[i] = oHScrollBox.eq(i).swiper({
                        freeMode: false,
                        freeModeMomentumRatio: 0.5,
                        lazyLoading: true,
                        watchSlidesProgress: true,
                        watchSlidesVisibility : true,
                        slideClass : 'slide-HScroll',
                        slidesPerView : 'auto',
                        observer: true,
                        observeParents: true,
                    });
                }
                else {
                    _this.oSlideAdsScroll[i].onResize();
                }
                _this.oSlideAdsScroll[i].slideTo(0, 0, false);

            });

        },

        // 设置icon图滚动广告
        SetAdsIconSwiper: function () {
            var _this = this;
            var oHScrollBox = $('.js_IconSwiper');
            oHScrollBox.each(function (i) {
                if(_this.oSlideAdsIconSwiper[i] === undefined) {
                    _this.oSlideAdsIconSwiper[i] = oHScrollBox.eq(i).swiper({
                        pagination: ".js_IconSwiperPagination",
                        // lazyLoading: true,
                        //lazyLoadingInPrevNextAmount: 4,
                        watchSlidesProgress: true,
                        watchSlidesVisibility : true,
                        slidesPerView : '5',
                        observer: true,
                        observeParents: true,
                        onSlideChangeEnd:function (swiper) {}
                    });
                }
                else {
                    _this.oSlideAdsIconSwiper[i].onResize();
                }
                _this.oSlideAdsIconSwiper[i].slideTo(0, 0, false);
            });

        },

        // 倒计时
        CutDataTime: function() {
            var _this = this;
            var oActTimeShow = $('.act-timeShow');
            var ss = _this.cutTimeToday()%60;
            var mm = ((_this.cutTimeToday() - ss)/60)%60;
            var hh = (_this.cutTimeToday() - _this.cutTimeToday() % 3600)/3600;
            ss = ss < 10 ? ('0' + ss) : ss;
            mm = mm < 10 ? ('0' + mm) : mm;
            hh = hh < 10 ? ('0' + hh) : hh;
            var sHtml = '<span class="timeShow timeBg-black">'+ hh +'</span><i>/</i>'+
                '<span class="timeShow timeBg-black">'+ mm +'</span><i>/</i>'+
                '<span class="timeShow timeBg-red">'+ ss +'</span>';
            if(oActTimeShow.length == 0) return;

            oActTimeShow.empty().append(sHtml);
            sHtml = null;
            clearTimeout(_this.time_CutTime);
            _this.time_CutTime = setTimeout(function () {
                _this.CutDataTime()
            }, 1000);

        },

        // 头条跑马灯
        RunHouse: function () {
            var _this = this;
            var oHotMessageUl = $('.js_hotMessage ul');
            oHotMessageUl.append(oHotMessageUl.html());
            var oHotMessageLI = oHotMessageUl.find('li');

            var oLiH = parseInt(oHotMessageLI.outerHeight(true));
            var nLilength = oHotMessageLI.length;
            var disUlTop = 0;

            oHotMessageUl.css({'top': -disUlTop});
            oHotMessageUl.on('touchstart', function () {
                clearTimeout(_this.time_RunHouse);
            });
            oHotMessageUl.on('touchend', function () {
                _this.time_RunHouse = setTimeout(Move,2500)
            });
            Move();
            function Move() {
                if(disUlTop >= oLiH * (nLilength-1) /2) {
                    disUlTop = oLiH;
                    oHotMessageUl.stop().animate({'top': -disUlTop},300);
                } else {
                    disUlTop += oLiH;
                    oHotMessageUl.stop().animate({'top': -disUlTop}, 300, function () {
                        if(disUlTop == oLiH * nLilength/2) {
                            oHotMessageUl.stop().animate({'top': 0},0)
                        }
                    });
                }
                clearTimeout(_this.time_RunHouse);
                _this.time_RunHouse = setTimeout(Move,2500)
            }
        },

        // 当天倒计时
        cutTimeToday: function () {
            var date = new Date();
            date.setMilliseconds(0);

            var nowDate = date.getTime();
            date.setHours(0);
            date.setMinutes(0);
            date.setSeconds(0);
            date.setDate(date.getDate() + 1);
            var nextDay = date.getTime();
            var diffTime = (nextDay - nowDate) / 1000;
            return diffTime
        }
    }

    exports.adsInit = adsInit;

    var adsHtml = {
        oSildeNavJRoll : [],            // 文字导航横向滚动条
        oSildeImgNavJRoll : [],         // 图片导航横向滚动条
        scrollTextWidth: [],            // 文字导航每次点击滚动的宽度
        scrollImgWidth: [],             // 图片导航每次点击滚动的宽度
        couponTap: true,                // 领取优惠券防止双击
        coupon_timer: null,             // 优惠券防止双击定时器

        // 广告banner  1行一个,自定义属性 _href 按照返回的 cLink 来设置；
        AdsBanner: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var shtml = '';
            var adItems = JSON.parse(advertItem.items);
            // console.log('1行一个',adItems);
            for (var i=0; i<adItems.length; i++) {
                var item = adItems[i];

                var cLink = _this.GetAdsLink(item.linkType,item.link);
                //判断是否是配返回首页的情况
                if(advertItem.moduleName.indexOf('返回首页') > -1){
                    shtml += '<li><a class="js_changeHref" _href="home" data-growing-title="'+advertItem.moduleName+i+'"><img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+i+'"></a></li>';
                }else {
                    shtml += '<li><a href="' + cLink + '" _href="' + cLink + '" data-growing-title="'+advertItem.moduleName+i+'"><img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+i+'"></a></li>';
                }

            }
            var shtmlBox =
                '<section class="AdsImgShow AdsImgShow js_AdsImgShowBanner js_moduleArea" id="list'+num+'">'+
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '       <div class="AdsImgShowBox">'+
                '           <div class="AdsImgShowBanner HBox BoxCenter">' +
                '               <div class="Ads-bannerList Bflex1">' +
                '                   <ul>'+ shtml +'</ul>' +
                '               </div>'+
                '            </div>'+
                '       </div>'+
                '   </div>'+
                '</section>';
            var $shtmlBox = $(shtmlBox);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $shtmlBox.addClass("AdsInterval_gray")
            }

            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($shtmlBox);
            //如果有返回首页的元素就要更改链接
            // myPub.JudgeAppHref($(shtmlBox).find('a'))
            myPub.JudgeAppHref($('.js_AdsImgShowBanner').find('a'));

            shtml = null;
            shtmlBox = null;
            oSlidePageScroll = null;
            adItems = null;
        },

        // 横排分类广告 ，自定义属性 _href 按照返回的 cLink 来设置；
        AdsHorizontal: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var shtml = '';
            var adItems = JSON.parse(advertItem.items);
            var shtmlBox = '';
            // console.log('横排分类广告',adItems);
            if (adItems.length < 6) {
                for (var i=0; i < adItems.length; i++) {
                    var item = adItems[i];
                    var cLink = _this.GetAdsLink(item.linkType,item.link);

                    shtml += '<li class="Bflex1">' +
                        '            <a href="' + cLink + '" _href="' + cLink + '" data-growing-title="'+advertItem.moduleName+i+'">' +
                        '               <figure>' +
                        '                   <img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+i+'">' +
                        '               </figure>' +
                        // '            <aside>'+item.title+'</aside>' +
                        '            </a>' +
                        '          </li>';

                }
                shtmlBox +=
                    '<section class="AdsImgShow ads-hor-finite js_ads-hor-finite js_moduleArea" id="list'+num+'">' +
                    '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                    '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+';padding-left:0;padding-right:0;">'+
                    '       <div class="ads-horList" style="background-image: url(' + HTTP_IMAGE_URL + advertItem.backgroundImg + ');background-size: 100% 100%;background-repeat: no-repeat;">'+
                    '           <ul class="HBox BoxCenter">'+ shtml + '</ul>' +
                    '       </div>'+
                    '   </div>'+
                    '</section>';
            }else if (adItems.length == 6){
                for (var i=0; i < adItems.length; i++) {
                    var item = adItems[i];
                    var cLink = _this.GetAdsLink(item.linkType,item.link);


                    shtml +=
                        '<div class="swiper-slide">' +
                        '   <a href="' + cLink + '" _href="' + cLink + '" data-growing-title="'+advertItem.moduleName+i+'">' +
                        '      <figure>' +
                        '         <img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+i+'">' +
                        '      </figure>' +
                        // '   <aside>'+item.title+'</aside>' +
                        '    </a>' +
                        '</div>';


                }
                shtmlBox +=
                    '<section class="AdsImgShow ads-hor-finiteScroll js_moduleArea" id="list'+num+'">' +
                    '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                    '   <div class="AdsImgMain act-noPadding js_AdsImgMain"  style="background-color: #'+advertItem.backgroundColor+';padding-left:0;padding-right:0;">'+
                    '       <div class="ads-horList" style="background-image: url(' + HTTP_IMAGE_URL + advertItem.backgroundImg + ');background-size: 100% 100%;background-repeat: no-repeat;">'+
                    '           <div class="swiper-container js_IconSwiper">'+
                    '               <div class="swiper-wrapper">'+
                    shtml +
                    '               </div>' +
                    '               <div class="swiper-pagination js_IconSwiperPagination"></div>'+
                    '           </div>' +
                    '       </div>'+
                    '   </div>'+
                    '</section>';
            }
            var $shtmlBox = $(shtmlBox);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $shtmlBox.addClass("AdsInterval_gray")
            }

            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($shtmlBox);

            // 检测图片加载完成后处理
            var AdsHorImg =  oSlidePageScroll.eq(iNow).find('.js_ads-hor-finite img');
            var _iNum = 0;
            AdsHorImg.hide();
            AdsHorImg.each(function (i) {
                AdsHorImg[i].onload = function () {
                    _iNum++;
                    if(_iNum == AdsHorImg.length) {
                        AdsHorImg.parents('figure').css({'height': 'auto'});
                        AdsHorImg.show();
                    }
                }
            });
            // oSlidePageScroll.eq(iNow).find('.js_ads-hor-finite figure').css({'height': 'auto'});

            myPub.JudgeAppHref($('.ads-hor-finiteScroll').find('a'));

            shtml = null;
            shtmlBox = null;
            oSlidePageScroll = null;
            adItems = null;
            adsInit.SetAdsIconSwiper();
        },

        // 横排分类广告 Min , 自定义属性 _href 按照返回的 cLink 来设置；
        AdsHorizontalMin: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var shtml = '';
            var adItems = JSON.parse(advertItem.items);
            var shtmlBox = '';
            // console.log('横排分类广告 Min',adItems);
            if (adItems.length < 6) {
                for (var i = 0; i < adItems.length; i++) {
                    var item = adItems[i];
                    var cLink = _this.GetAdsLink(item.linkType, item.link);
                    shtml += '<li class="Bflex1">' +
                        '           <a href="' + cLink + '" _href="' + cLink + '" data-growing-title="' + advertItem.moduleName + i + '">' +
                        '               <figure>' +
                        '                   <img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="' + advertItem.moduleName + i + '">' +
                        '               </figure>' +
                        '           </a>' +
                        '         </li>';

                }
                shtmlBox +=
                    '<section class="AdsImgShow ads-hor-finite js_ads-hor-finite-min act-noPadding js_moduleArea" id="list'+num+'">' +
                    '   <div class="ads-white-interval" style="background-color: #' + advertItem.topIntervalColor + '"></div>' +
                    '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+';padding-left:0;padding-right:0;">' +
                    '       <div class="ads-horList-min" style="background-image: url(' + HTTP_IMAGE_URL + advertItem.backgroundImg + ');background-size: 100% 100%;background-repeat: no-repeat;">' +
                    '           <ul class="HBox BoxCenter">' + shtml + '</ul>' +
                    '       </div>' +
                    '   </div>' +
                    '</section>';
            }else if (adItems.length == 6){
                for (var i=0; i < adItems.length; i++) {
                    var item = adItems[i];
                    var cLink = _this.GetAdsLink(item.linkType,item.link);
                    shtml +=
                    '<div class="swiper-slide">' +
                    '   <a href="' + cLink + '" _href="' + cLink + '" data-growing-title="'+advertItem.moduleName+i+'">' +
                    '      <figure>' +
                    '         <img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+i+'">' +
                    '      </figure>' +
                    '    </a>' +
                    '</div>';
                }
                shtmlBox +=
                    '<section class="AdsImgShow ads-hor-finiteScroll js_ads-hor-finite-min js_moduleArea" id="list'+num+'">' +
                    '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                    '   <div class="AdsImgMain act-noPadding js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+';padding-left:0;padding-right:0;">'+
                    '       <div class="ads-horList"  style="background-image: url(' + HTTP_IMAGE_URL + advertItem.backgroundImg + ');background-size: 100% 100%;background-repeat: no-repeat;">'+
                    '           <div class="swiper-container js_IconSwiper">'+
                    '               <div class="swiper-wrapper">'+
                    shtml +
                    '               </div>' +
                    '           <div class="swiper-pagination js_IconSwiperPagination"></div>'+
                    '           </div>' +
                    '       </div>'+
                    '   </div>'+
                    '</section>';
            }
            var $shtmlBox = $(shtmlBox);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $shtmlBox.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($shtmlBox);
            // 检测图片加载完成后处理
            var AdsHorImg =  oSlidePageScroll.eq(iNow).find('.js_ads-hor-finite-min img');
            var _iNum = 0;
            AdsHorImg.hide();
            AdsHorImg.each(function (i) {
                AdsHorImg[i].onload = function () {
                    _iNum++;
                    if(_iNum == AdsHorImg.length) {
                        AdsHorImg.parents('figure').css({'height': 'auto'});
                        AdsHorImg.show();
                    }
                }
            });
            myPub.JudgeAppHref($('.ads-hor-finiteScroll').find('a'));

            shtml = null;
            shtmlBox = null;
            oSlidePageScroll = null;
            adItems = null;
            adsInit.SetAdsIconSwiper();
        },

        // 广告组2个图 ，自定义属性 _href 按照返回的 cLink 来设置；
        AdsGroup2: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            // console.log('广告组2个图',adItems);
            if(adItems.length != 2){
                return;
            }
            var cLink0 = _this.GetAdsLink(adItems[0].linkType,adItems[0].link);
            var cLink1 = _this.GetAdsLink(adItems[1].linkType,adItems[1].link);


            var sectionHtml =
                '<section class="AdsImgShow js_AdsGroup2 AdsGroup2 js_moduleArea" id="list'+num+'">' +
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '       <div class="AdsImgShowBox">' +
                '           <div class="AdsImgShow1-1 HBox">' +
                '               <div class="AdsImg-href-left Bflex1">' +
                '                   <ul class="VBox">' +
                '                       <li class="Bflex1">' +
                '                           <a href="' + cLink0 + '" _href="' + cLink0 + '" data-growing-title="'+advertItem.moduleName+0+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[0].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+0+'">' +
                '                           </a>' +
                '                       </li>' +
                '                   </ul>' +
                '                </div>' +
                '                <div class="AdsImg-href-right Bflex1 ">' +
                '                   <ul class="VBox">' +
                '                       <li class="Bflex1">' +
                '                           <a href="' + cLink1 + '" _href="' + cLink1 + '" data-growing-title="'+advertItem.moduleName+1+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[1].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+1+'">' +
                '                           </a>' +
                '                       </li>' +
                '                   </ul>' +
                '               </div>' +
                '           </div>' +
                '       </div>' +
                '   </div>'+
                '</section>';




            var $sectionHtml = $(sectionHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $sectionHtml.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($sectionHtml);

            myPub.JudgeAppHref($('.AdsGroup2').find('a'))
            sectionHtml = null;
            oSlidePageScroll = null;
            adItems = null;
        },

        // 广告组3个图，自定义属性 _href 按照返回的 cLink 来设置；
        AdsGroup3: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            // console.log('广告组3个图',adItems);
            if(adItems.length != 3){
                return;
            }
            var cLink0 = _this.GetAdsLink(adItems[0].linkType,adItems[0].link);
            var cLink1 = _this.GetAdsLink(adItems[1].linkType,adItems[1].link);
            var cLink2 = _this.GetAdsLink(adItems[2].linkType,adItems[2].link);

            var sectionHtml =
                '<section class="AdsImgShow AdsImgShow AdsGroup3 js_AdsGroup3 js_moduleArea" id="list'+num+'">' +
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '       <div class="AdsImgShowBox">' +
                '           <div class="AdsImgShow1-2 HBox">' +
                '               <div class="AdsImg-href-left">' +
                '                   <ul class="VBox">' +
                '                       <li class="Bflex1">' +
                '                           <a href="' + cLink0 + '" _href="' + cLink0 + '"  data-growing-title="'+advertItem.moduleName+0+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[0].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+0+'">' +
                '                           </a>' +
                '                       </li>' +
                '                   </ul>' +
                '                </div>' +
                '                <div class="AdsImg-href-right VBox Bflex1 ">' +
                '                   <ul class="VBox Bflex1">' +
                '                       <li class="Bflex1">' +
                '                           <a href="' + cLink1 + '" _href="' + cLink1 + '" data-growing-title="'+advertItem.moduleName+1+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[1].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+1+'">' +
                '                           </a>' +
                '                       </li>' +
                '                       <li class="Bflex1">' +
                '                           <a href="' + cLink2 + '" _href="' + cLink2 + '" data-growing-title="'+advertItem.moduleName+2+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[2].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+2+'">' +
                '                           </a>' +
                '                       </li>' +
                '                   </ul>' +
                '               </div>' +
                '           </div>' +
                '       </div>' +
                '   </div>'+
                '</section>';

            var $sectionHtml = $(sectionHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $sectionHtml.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($sectionHtml);

            myPub.JudgeAppHref($('.AdsGroup3').find('a'))

            sectionHtml = null;
            oSlidePageScroll = null;
            adItems = null;
        },

        // 广告组5个图
        AdsGroup5: function () {},

        // 今日头条，自定义属性 _href 按照返回的 cLink 来设置；
        AdsHeadline: function (advertItem, iNow,num) {
            var _this = this;
            // console.log('AdsHeadline',advertItem);
            var oSlidePageScroll = $('.js_slidePageScroll');
            var boxHtml =
                '<section class="AdsImgShow ads-hotMessage js_moduleArea" id="list'+num+'">' +
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '   </div>'+
                '</section>';
            var $htmlBox = $(boxHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $htmlBox.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);
            var headlineUrl = BASE_URL + "/news/getShowNews";
            G_JSON_POST(headlineUrl,{},function (data) {
                if(data.length <= 0){
                    return;
                }
                var listHtml =
                    '<div class="hotMessage HBox BoxCenter border_top">' +
                    '   <figure>' +
                    '       <img src="' + BASE_URL + '/static_v4/image/icons-ads/icon-ddjads-hotMessage.png" alt="">' +
                    // '    <span class="splitline"></span>' +
                    '   </figure>' +
                    '   <div class="hotMessage-text Bflex1 js_hotMessage">' +
                    '      <ul class="headLineList">' +
                    '      </ul>' +
                    '   </div>' +
                    '</div>';
                var $listHtml = $(listHtml);
                $htmlBox.find('.js_AdsImgMain').append($listHtml);
                var $headlineList = $listHtml.find('.headLineList');
                for (var idx = 0; idx < data.length; idx ++){
                    var item = data[idx];
                    var headlineLi = '';
                    var _href = '';
                    var _typeId = '';
                    var _signHtml = '<span class="iconStyle icon-rob"></span>';
                    // 判断是商品链接还是新闻链接
                    item.type == 1 ?  _href = BASE_URL + '/h/goodspay/goodsView/' : _href = BASE_URL + '/news/detail/';
                    if(item.type == 1) {
                        _href = BASE_URL + '/h/goodspay/goodsView/';
                        _typeId = item.goodsSn;

                    }
                    else {
                        _href = BASE_URL + '/news/detail/';
                        _typeId = item.id;
                    }

                    // 判断是否添加抢购标记
                    // if(item.type == 2) {
                    //     _signHtml = '<span class="iconStyle icon-rob"></span>'；
                    // }

                    headlineLi = '<li><a class="HBox BoxCenter" href="' + _href + _typeId + '" _href="' + _href + _typeId + '">'+ _signHtml +'<span class="Bflex1">' + item.title + '</span></a></li>';

                    $headlineList.append(headlineLi);
                }

                adsInit.RunHouse();
                myPub.JudgeAppHref($('.headLineList').find('a'));
                boxHtml = null;
                listHtml = null;
                oSlidePageScroll = null;
                data = null;

            }, function () {
                adsAjax.lockScroll();
            }, function () {
                adsAjax.unlockScroll();
            });
        },

        // 1+4，自定义属性 _href 按照返回的 cLink 来设置；
        AdsOneFour: function (advertItem, iNow,num) {
            var _this = this;
            var adItems = JSON.parse(advertItem.items);
            // console.log('1+4',adItems);
            // console.log('---',adItems,advertItem)
            var link0 = _this.GetAdsLink(adItems[0].linkType,adItems[0].link);
            var link1 = _this.GetAdsLink(adItems[1].linkType,adItems[1].link);
            var link2 = _this.GetAdsLink(adItems[2].linkType,adItems[2].link);
            var link3 = _this.GetAdsLink(adItems[3].linkType,adItems[3].link);
            var link4 = _this.GetAdsLink(adItems[4].linkType,adItems[4].link);


            if(adItems.length == 6){
                var link5 = _this.GetAdsLink(adItems[5].linkType,adItems[5].link);

                var titleImage = HTTP_IMAGE_URL + adItems[0].titleImage;


                var advertHtml = [
                    '<section class="AdsImgShow AdsImgShow AdsGroup1-4 js_moduleArea" id="list'+num+'">',
                    '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>',
                    '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">',
                    '	    <!--<div class="goods_title HBox">-->',
                    '	    	<!--<img src="' + titleImage + '" alt="">-->',
                    '	    <!--</div>-->',
                    '	    <!-- 1+4广告  -->',
                    '	    <div class="AdsImgShowBox">',
                    '	    	<div class="AdsImgShow1-4 HBox">',
                    '	    		<div class="AdsImg-href-left">',
                    '	    			<ul class="VBox">',
                    '	    				<li class="Bflex1"><a href="' + _this.GetAdsLink(adItems[1].linkType,adItems[1].link) + '" _href="' + link1 + '"  data-growing-title="'+advertItem.moduleName+1+'">' +
                    '                           <img src="' + HTTP_IMAGE_URL + adItems[1].imageUrl + '" alt=""  data-growing-title="'+advertItem.moduleName+1+'"></a></li>',
                    '	    			</ul>',
                    '	    		</div>',
                    '	    		<div class="AdsImg-href-right VBox Bflex1 ">',
                    '	    			<ul class="VBox Bflex1">',
                    '	    				<li class="Bflex1 HBox">',
                    '	    					<div class="Bflex1 left_Box"><a href="' + _this.GetAdsLink(adItems[2].linkType,adItems[2].link) + '" _href="' + link2 + '"  data-growing-title="'+advertItem.moduleName+2+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[2].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+2+'"></a></div>',
                    '	    					<div class="Bflex1 right_Box"><a href="' + _this.GetAdsLink(adItems[3].linkType,adItems[3].link) + '" _href="' + link3 + '" data-growing-title="'+advertItem.moduleName+3+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[3].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+3+'"></a></div>',
                    '	    				</li>',
                    '	    				<li class="Bflex1 HBox">',
                    '	    					<div class="Bflex1 left_Box"><a href="' + _this.GetAdsLink(adItems[4].linkType,adItems[4].link) + '" _href="' + link4 + '" data-growing-title="'+advertItem.moduleName+4+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[4].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+4+'"></a></div>',
                    '	    					<div class="Bflex1 right_Box"><a href="' + _this.GetAdsLink(adItems[5].linkType,adItems[5].link) + '" _href="' + link5 + '" data-growing-title="'+advertItem.moduleName+5+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[5].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+5+'"></a></div>',
                    '	    				</li>',
                    '	    			</ul>',
                    '	    		</div>',
                    '	    	</div>',
                    '	    </div>',
                    '   </div>',
                    '</section>'].join("");
            }
            else if(adItems.length == 5){
                var titleImage = HTTP_IMAGE_URL + adItems[0].titleImage;
                var advertHtml = [
                    '<section class="AdsImgShow AdsImgShow AdsGroup1-4 js_moduleArea" id="list'+num+'">',
                    '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>',
                    '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">',
                    '	    <!--<div class="goods_title HBox">-->',
                    '	    	<!--<img src="' + titleImage + '" alt="">-->',
                    '	    <!--</div>-->',
                    '	    <!-- 1+4广告  -->',
                    '	    <div class="AdsImgShowBox">',
                    '	    	<div class="AdsImgShow1-4 HBox">',
                    '	    		<div class="AdsImg-href-left">',
                    '	    			<ul class="VBox">',
                    '	    				<li class="Bflex1"><a href="' + _this.GetAdsLink(adItems[0].linkType,adItems[0].link) + '" _href="' + link0 + '" data-growing-title="'+advertItem.moduleName+1+'">' +
                    '                           <img src="' + HTTP_IMAGE_URL + adItems[0].imageUrl + '" alt=""  data-growing-title="'+advertItem.moduleName+0+'"></a></li>',
                    '	    			</ul>',
                    '	    		</div>',
                    '	    		<div class="AdsImg-href-right VBox Bflex1 ">',
                    '	    			<ul class="VBox Bflex1">',
                    '	    				<li class="Bflex1 HBox">',
                    '	    					<div class="Bflex1 left_Box"><a href="' + _this.GetAdsLink(adItems[1].linkType,adItems[1].link) + '" _href="' + link1 + '" data-growing-title="'+advertItem.moduleName+1+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[1].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+1+'"></a></div>',
                    '	    					<div class="Bflex1 right_Box"><a href="' + _this.GetAdsLink(adItems[2].linkType,adItems[2].link) + '" _href="' + link2 + '" data-growing-title="'+advertItem.moduleName+2+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[2].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+2+'"></a></div>',
                    '	    				</li>',
                    '	    				<li class="Bflex1 HBox">',
                    '	    					<div class="Bflex1 left_Box"><a href="' + _this.GetAdsLink(adItems[3].linkType,adItems[3].link) + '" _href="' + link3 + '" data-growing-title="'+advertItem.moduleName+3+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[3].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+3+'"></a></div>',
                    '	    					<div class="Bflex1 right_Box"><a href="' + _this.GetAdsLink(adItems[4].linkType,adItems[4].link) + '" _href="' + link4 + '" data-growing-title="'+advertItem.moduleName+4+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[4].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+4+'"></a></div>',
                    '	    				</li>',
                    '	    			</ul>',
                    '	    		</div>',
                    '	    	</div>',
                    '	    </div>',
                    '   </div>',
                    '</section>'].join("");
            }else {
                return;
            }
            // console.log('---',adItems);


            var $advertHtml = $(advertHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $advertHtml.addClass("AdsInterval_gray")
            }
            var oSlidePageScroll = $('.js_slidePageScroll');
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($advertHtml);
            myPub.JudgeAppHref($('.AdsGroup1-4').find('a'))
            adItems = null;
            advertHtml = null;
        },

        // 水平滚动产品，自定义属性 _href 按照返回的 cLink 来设置；
        GoodsHScroll: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var goodsList = advertItem.groupGoodsVoList;        // 商品列表
            var adItems = JSON.parse(advertItem.items);
            // console.log('水平滚动产品1',adItems);
            var boxHtml =
                '<div class="AdsImgShow goods_HScroll js_goods_HScroll whiteAModule js_moduleArea" id="list'+num+'">' +
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '       <div class="swiper-container goodsBox_HScroll js_HScroll ">' +
                '           <div class="swrap-HScroll swiper-wrapper goodsList js_goodsListScroll" >' +
                '           </div>' +
                '       </div>' +
                '   </div>'+
                '</div>';
            var $htmlBox = $(boxHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $htmlBox.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);

            var $goodsList = $htmlBox.find('.js_goodsListScroll');

            if(goodsList && goodsList.length>0){
                var goodsHtml = '';
                for (var idx = 0; idx < goodsList.length; idx ++){
                    var item = goodsList[idx];
                    //全额保障  选择性显示哪些右上角图标
                    var firstGueeImagePath=item.firstGueeImagePath;
                    var gueeUrlHtml = '';
                    if(firstGueeImagePath!=null && firstGueeImagePath!=""){
                        gueeUrlHtml='<img src="'+BASE_URL+'/static_v4/image/iconPic/'+firstGueeImagePath+'"alt="" class="quanpei"/>';
                    }
                    //活动标签
                    var labelHtml = '';
                    var headHotHtml = '';
                    if(item.goodsLabel && item.goodsLabel != ''){
                        labelHtml = '<div class="verpromotionHot"><span>'+ item.goodsLabel +'</span><div><img src="' + BASE_URL + '/static_v4/image/iconImg/hotIcon.png" alt=""></div></div>';
                        headHotHtml = '<i class="promotionHotIcon">'+ item.goodsLabel +'</i>'
                    }
                    var url = BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn;


                    goodsHtml += '' +
                        '<div class="slide-HScroll swiper-slide">' +
                        '   <a href="' + BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn + '"  _href="'+url+'" data-growing-title="'+item.name+'">' +
                        '       <figure>' +
                        '           <img class="swiper-lazy" data-src="' + HTTP_IMAGE_URL + item.goodsDefaultImage + smallImgArg300 +'" src="' + BASE_URL + '/static_v4/image/loadImg.jpg" data-growing-title="'+item.goodsName+'">' +
                        gueeUrlHtml+
                        labelHtml+
                        '       </figure>' +
                        '       <aside class="priceArea VBox Bflex1">' +
                        '           <div class="Bflex1 priceArea_name">' +
                        '               <h4>' + headHotHtml + item.goodsName + '</h4>' +
                        '               <div class="smallFont_tip">' + item.productName + '</div>' +
                        '               </div>' +
                        '           <div class="priceArea_price">' +
                        '               <div class="HBox priceAreaBox">' +
                        '                   <span class="goodsPrice">￥' + item.salePrice + '</span>' +
                        '               </div>' +
                        '           </div>' +
                        '       </aside>' +
                        '   </a>' +
                        '</div>';
                }
                $goodsList.append(goodsHtml);
                adsInit.SetAdsLiScroll();
                myPub.JudgeAppHref($('.goods_HScroll').find('a'));
                // 插入产品标题
                $goodsList.parents('.js_AdsImgMain').prepend(_this.TitleHtml(adItems[0].moduleTitle, adItems[0].timerType));
                adsInit.CutDataTime();
            }
        },

        // 暂时没用团购水平滚动产品----拼单--增加查看更多，自定义属性 _href 按照返回的 cLink 来设置；
        GoodsHScrollMore: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            // console.log('水平滚动产品',adItems);
            var boxHtml =
                '<div class="AdsImgShow goods_HScroll js_goods_HScroll whiteAModule" id="list'+num+'">' +
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '       <div class="swiper-container goodsBox_HScroll js_HScroll ">' +
                '           <div class="swrap-HScroll swiper-wrapper goodsList js_goodsListScroll" >' +
                '           </div>' +
                '       </div>' +
                '   </div>'+
                '</div>';
            var $htmlBox = $(boxHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $htmlBox.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);

            var $goodsList = $htmlBox.find('.js_goodsListScroll');

            var goodsGroupUrl = BASE_URL + adItems[0].tuangouGoodsUrl;
            var data = {groupName:adItems[0].goodsGroupName,start:0,limit:20};
            G_JSON_GET(goodsGroupUrl,data,function (data) {
                var datas = data.result;
                var goodsHtml = '';
                if(datas.length <= 0){
                    return;
                }
                for (var idx = 0; idx < datas.length; idx ++){
                    var item = datas[idx];

                    //全额保障  选择性显示哪些右上角图标
                    var firstGueeImagePath=item.firstGueeImagePath;
                    var gueeUrlHtml = '';
                    if(firstGueeImagePath!=null && firstGueeImagePath!=""){
                        gueeUrlHtml='<img src="'+BASE_URL+'/static_v4/image/iconPic/'+firstGueeImagePath+'"alt="" class="quanpei"/>';
                    }
                    //活动标签
                    var labelHtml = '';
                    var headHotHtml = '';
                    if(item.goodsLabel && item.goodsLabel != ''){
                        labelHtml = '<div class="verpromotionHot"><span>'+ item.goodsLabel +'</span><div><img src="' + BASE_URL + '/static_v4/image/iconImg/hotIcon.png" alt=""></div></div>';
                        headHotHtml = '<i class="promotionHotIcon">'+ item.goodsLabel +'</i>'
                    }

                    //多活动标签
                    var goodsLabelHtml = '';
                    if(item.label && item.label != ''){
                        var eachLabelHtml = '';
                        for(var i=0;i<item.labels.length;i++){
                            eachLabelHtml += '<i>'+item.labels[i]+'</i>'
                        }
                        goodsLabelHtml += '<p class="promotionSale">'+
                            eachLabelHtml+
                            '</p>';
                    }
                    var url = BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn;
                    goodsHtml += '' +
                        '<div class="slide-HScroll swiper-slide">' +
                        '   <a href="' + BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn + '" _href="'+ url +'" data-growing-title="'+item.name+'">' +
                        '       <figure class="pintuan_radius">' +
                        '           <img class="swiper-lazy" data-src="' + HTTP_IMAGE_URL + item.showImage + smallImgArg300 +'" src="' + BASE_URL + '/static_v4/image/loadImg.jpg" data-growing-title="'+item.name+'">' +
                        gueeUrlHtml+
                        labelHtml+
                        '       </figure>' +
                        '       <aside class="priceArea VBox Bflex1 collageArea pindanArea">' +
                        '           <div class="Bflex1 priceArea_name">' +
                        '               <h4>' + headHotHtml + item.name + '</h4>' +
                        '               <div class="smallFont_tip">' + item.title + '</div>' +
                        '           </div>' +
                        '           <div class="priceArea_price">' +
                        '               <div class="HBox priceAreaBox">' +
                        '                   <span class="goodsPrice">￥' + item.tuangouPrices
                        + '</span>' +
                        '                   <span class="goodsPriceOld goodSalePrice">￥' + item.salePrice

                        + '</span>' +
                        '               </div>' +
                        '           </div>'+
                        goodsLabelHtml+
                        '       </aside>' +
                        '   </a>' +
                        '</div>';
                }
                $goodsList.append(goodsHtml);
                adsInit.SetAdsLiScroll();
                myPub.JudgeAppHref($('.js_goods_HScroll').find('a'))

                boxHtml = null;
                goodsHtml = null;
                oSlidePageScroll = null;
                item = null;

            }, function () {
                adsAjax.lockScroll();
            }, function () {
                adsInit.SetAdsLiScroll();
                adsAjax.unlockScroll();



                // 插入产品标题
                $goodsList.parents('.js_AdsImgMain').prepend(_this.TitleMoreHtml(adItems[0].moduleTitle, adItems[0].timerType,adItems[0].viewMoreUrl));
                adsInit.CutDataTime();
            });
        },

        // 广告图+商品滚动，自定义属性 _href 按照返回的 cLink 来设置；
        AdsAndScroll: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var goodsList = advertItem.groupGoodsVoList;            // 商品列表
            var adItems = JSON.parse(advertItem.items);
            // console.log('广告图+商品滚动',adItems);
            // console.log('hahah++',advertItem);
            if(adItems.length != 1){
                return;
            }
            var item = adItems[0];
            var cLink = _this.GetAdsLink(item.linkType,item.link);

            var adsImg =
                '<section class="AdsImgShow AdsImgShow AdsImgShowBannerScroll js_AdsImgShowBannerScroll js_moduleArea" id="list'+num+'">' +
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">'+
                '       <div class="AdsImgShowBox">'+
                '           <div class="AdsImgShowBanner HBox BoxCenter">' +
                '               <div class="Ads-bannerList Bflex1">' +
                '                   <ul>'+
                '                       <li><a href="' + cLink + '" _href="' + cLink + '" data-growing-title="'+advertItem.moduleName+'"><img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+'"></a></li>' +
                '                   </ul>' +
                '               </div>'+
                '           </div>'+
                '       </div>' +
                '   </div>'+
                '</section>';
            var goodsScrollBox =
                '<div class="goods_HScroll goods_HScroll-sm js_goods_HScroll">' +
                '   <div class="swiper-container goodsBox_HScroll js_HScroll ">' +
                '   <div class="swrap-HScroll swiper-wrapper goodsList" >' +
                '   </div>' +
                '   </div>' +
                '</div>';
            var $scrollBox = $(goodsScrollBox);
            var $adsImg = $(adsImg);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $adsImg.addClass("AdsInterval_gray")
            }
            $adsImg.find('.js_AdsImgMain').append($scrollBox);
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($adsImg);

            adsImg = null;
            goodsScrollBox = null;

            var $goodsList = $scrollBox.find('.goodsList');
            if(goodsList && goodsList.length>0){
                for (var idx = 0; idx < goodsList.length; idx ++){
                    var item = goodsList[idx];

                    //全额保障  选择性显示哪些右上角图标
                    var firstGueeImagePath=item.firstGueeImagePath;
                    var gueeUrlHtml = '';
                    if(firstGueeImagePath!=null && firstGueeImagePath!=""){
                        gueeUrlHtml='<img src="'+BASE_URL+'/static_v4/image/iconPic/'+firstGueeImagePath+'"alt="" class="quanpei"/>';
                    }
                    //活动标签
                    var labelHtml = '';
                    var headHotHtml = '';
                    if(item.goodsLabel && item.goodsLabel != ''){
                        labelHtml = '<div class="verpromotionHot"><span>'+ item.goodsLabel +'</span><div><img src="' + BASE_URL + '/static_v4/image/iconImg/hotIcon.png" alt=""></div></div>';
                        headHotHtml = '<i class="promotionHotIcon">'+ item.goodsLabel +'</i>'
                    }
                    var url = BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn;

                    var goodsHtml =
                        '<div class="slide-HScroll swiper-slide">' +
                        '   <a href="' + BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn + '" _href="'+ url +'" data-growing-title="'+item.goodsName+'">' +
                        '       <figure>' +
                        '           <img class="swiper-lazy" data-src="' + HTTP_IMAGE_URL + item.goodsDefaultImage + smallImgArg300 +'" src="' + BASE_URL + '/static_v4/image/loadImg.jpg"  data-growing-title="'+item.goodsName+'">' +
                        gueeUrlHtml+
                        labelHtml+
                        '       </figure>' +
                        '       <aside class="priceArea VBox Bflex1">' +
                        '           <div class="Bflex1 priceArea_name">' +
                        '               <h4>' + headHotHtml + item.goodsName + '</h4>' +
                        '               <div class="smallFont_tip">' + item.productName + '</div>' +
                        '           </div>' +
                        '           <div class="priceArea_price">' +
                        '               <div class="HBox priceAreaBox">' +
                        '                   <span class="goodsPrice">￥' + item.salePrice + '</span>' +
                        '               </div>' +
                        '           </div>' +
                        '       </aside>' +
                        '   </a>' +
                        '</div>';
                    $goodsList.append(goodsHtml);

                    myPub.JudgeAppHref($('.js_AdsImgShowBannerScroll').find('a'));

                    goodsHtml = null;
                    item = null;
                    adsInit.SetAdsLiScroll();
                }
            }
        },

        // 商品旋转滚动轮播，自定义属性 _href 按照返回的 cLink 来设置；
        AdsGoodsBanner: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            // console.log('商品旋转滚动轮播',adItems);
            if(adItems.length != 1){
                return;
            }
            var item = adItems[0];
            var title = item.moduleTitle;
            var goodsGroupName = item.goodsGroupName;
            var htmlBox = [
                '<section class="AdsImgShow AdsHRotateBox js_moduleArea" id="list'+num+'">',
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>',
                '	<div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">',
                '	    <div class="goods_title HBox BoxCenter">',
                '	    	<div class="title_line"></div>',
                '	    	<div class="title_name">' + title + '</div>',
                '	    	<div class="title_line"></div>',
                '	    </div>',
                '	    <div class="swiper-container AdsHRotateSwiper js_HRotate">',
                '	    	<div class=" swiper-wrapper goodsList" >',
                '	    	</div>',
                '	    	<div class="swiper-pagination js_pagin "></div>',
                '	    </div>',
                '	</div>',
                '</section>'].join("");
            var $htmlBox = $(htmlBox);

            if(advertItem.spacing != null && advertItem.spacing == 1){
                $htmlBox.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);

            var $goodsList = $htmlBox.find('.goodsList');
            var goodsGroupUrl = BASE_URL + "/shop/goods/loadGoods";
            var data = {groupName:goodsGroupName,start:0,limit:20};

            G_JSON_POST(goodsGroupUrl,data,function (data) {
                if(data.length <= 0){
                    return;
                }
                for (var idx = 0; idx < data.length; idx ++){
                    var item = data[idx];
                    var salePrice = item.salePrice;
                    var priceInt = parseInt(salePrice);
                    var priceFloat = parseInt((salePrice - priceInt) * 10);
                    if(priceFloat == 0){
                        priceFloat = "";
                    }else{
                        priceFloat = "." + priceFloat;
                    }
                    var url = BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn;

                    var goodsHtml = [
                        '<div class="swiper-slide goodsList-slide">',
                        '	<a href="' + BASE_URL + '/h/goodspay/goodsView/' + item.goodsSn + '" _href="'+ url +'" data-growing-title="'+item.name+'">',
                        '		<figure>',
                        '			<img  src="' + HTTP_IMAGE_URL + item.showImage + smallImgArg300 +'"  data-growing-title="'+item.name+'">',
                        '		</figure>',
                        '		<aside class="priceArea Bflex1">',
                        '			<div class="Bflex1 priceArea_name">',
                        '				<h4>' + item.name + '</h4>',
                        '				<p class="smallFont_tip">' + item.title + '</p>',
                        '			</div>',
                        '			<div class="priceArea_price priceAreaAbs_price">',
                        '				<p class="priceAreaBox">',
                        '					<span class="goodsPrice"><i>￥</i>' + priceInt + '<i>' + priceFloat + '</i></span>',
                        '					<span class="splitline"></span>',
                        '					<span class="topNum">',
                        '					<i>-</i><i>Top' + (idx+1) + '</i><i>-</i>',
                        '				</span>',
                        '				</p>',
                        '			</div>',
                        '		</aside>',
                        '	</a>',
                        '</div>'].join("");
                    //全额保障  选择性显示哪些右上角图标
                    /*var firstGueeImagePath=item.firstGueeImagePath;
                    if(firstGueeImagePath!=null && firstGueeImagePath!=""){
                        var gueeUrl=firstGueeImagePath;
                        goodsHtml += '<img src="'+gueeUrl+'"alt="" class="quanpei"/>';
                    }*/
                    $goodsList.append(goodsHtml);

                    myPub.JudgeAppHref($('.AdsHRotateBox').find('a'))

                    goodsHtml = null;
                    item = null;
                }
                adsInit.SetAdsRotate();
            }, function () {
                adsAjax.lockScroll();
            }, function () {
                adsAjax.unlockScroll();
            });
        },

        // 图片滚动轮播，自定义属性 _href 按照返回的 cLink 来设置；
        AdsPicBanner: function (advertItem, iNow,num) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            var picBannerList = "";
            // console.log('图片轮播广告',adItems);
            for (var i=0; i < adItems.length; i++) {
                var item = adItems[i];
                var cLink = _this.GetAdsLink(item.linkType,item.link);

                picBannerList += [
                    '<div class="swiper-slide ">',
                    '	<a href="' + cLink + '" _href="' + cLink + '" data-growing-title="'+advertItem.moduleName+i+'">',
                    '		<figure>',
                    '			<img  src="' + HTTP_IMAGE_URL + item.imageUrl + '"  data-growing-title="'+advertItem.moduleName+i+'">',
                    '		</figure>',
                    '	</a>',
                    '</div>'
                ].join("");
            }
            var htmlBox = [
                '<section class="AdsImgShow AdsLong_HScrollBox js_moduleArea" id="list'+num+'">',
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>',
                '	<div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">',
                '		<div class="swiper-container AdsLong_HScrollSwiper js_AdsLong_HScrollSwiper">',
                '			<div class="swiper-wrapper longSwiper" >',
                                picBannerList,
                '			</div>',
                '           <div class="swiper-pagination js_pagin"></div>',
                '		</div>',
                '	</div>',
                '</section>'].join("");
            var $htmlBox = $(htmlBox);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $htmlBox.addClass("AdsInterval_gray")
            }
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);
            adsInit.SetAdsLongSwiper();

            myPub.JudgeAppHref($('.AdsLong_HScrollBox').find('a'))

            htmlBox = null;
            picBannerList = null;
        },

        GetAdsLink: function (linkType,link) {
            if(linkType == undefined || link == undefined){
                return BASE_URL;
            }

            if(linkType == 'GOODS_LINK'){
                // 跳转商详页
                return BASE_URL + '/h/goodspay/goodsView/' + link ;
            }
            else if(linkType == 'CUSTOM_LINK'){
                // 跳转自定义专题页面
                return BASE_URL+ '/hml/supplier_subject_page/'+link+'.html'
            }
            else if(linkType == 'H5_LINK'){
                // 跳转自定义链接
                return link
            }
            else{
                return BASE_URL
            }
        },

        getCoupon:function(sign) {
            var _this = this;
            if(!_this.couponTap)return;
            _this.couponTap = false;
            G_JSON_POST(drawCouponUrl,{
                'ruleSign' : sign
            },function (data) {
                var _data = data.data;
                var _ret = data.ret;
                if(_ret.code == '0'){
                    myPub.TipLayer('领取成功','no',function () {
                        _this.couponTap = true
                    });
                }
                else if(_ret.code == '00100'){
                    var url = window.location.href;
                    myPub.setCookie('historyLastUrl',url);
                    myPub.TipLayerEnd('您还未登录，请登录','no',function () {
                        _this.couponTap = true;
                        window.location.href = '/h/login/'
                    });
                }
                else{
                    myPub.TipLayer(_ret.message,'no',function () {
                        _this.couponTap = true
                    });
                }
            });
            clearTimeout(_this.coupon_timer);
            _this.coupon_timer = setTimeout(function () {
                _this.couponTap = true;
            },500)
        },

        // 产品标题
        TitleHtml: function (title, timerType) {
            if(title == undefined || title.length <= 0){
                return '';
            }
            var timer = '';
            if(timerType != undefined){
                if(timerType == 'DAY_TIMER'){
                    timer = '<div class="act-timeShow Bflex1">' +
                        '<span class="timeShow timeBg-black"></span><i>/</i>' +
                        '<span class="timeShow timeBg-black"></span><i>/</i>' +
                        '<span class="timeShow timeBg-red"></span></div>';
                }
            }
            // 标题信息
            var stitleTipText =  '<div class="goods_title HBox"><h5><span>' + title + '</span></h5>' + timer + '</div>';
            return stitleTipText;
        },

        // 产品标题增加拼单商品与查看更多链接
        TitleMoreHtml: function (title, timerType,moreUrl) {
            if(title == undefined || title.length <= 0){
                return '';
            }
            var timer = '';
            if(timerType != undefined){
                if(timerType == 'DAY_TIMER'){
                    timer = '<div class="act-timeShow Bflex1">' +
                        '<span class="timeShow timeBg-black"></span><i>/</i>' +
                        '<span class="timeShow timeBg-black"></span><i>/</i>' +
                        '<span class="timeShow timeBg-red"></span></div>';
                }
            }
            // 标题信息
            var stitleTipText =  '<div class="goods_title HBox"><h5><span>' + title + '</span></h5>' + timer +'<a class="index_addMore" href="'+moreUrl+'"><span>查看更多</span> <i class="iconStyle icon-href-right"></i></a>'+ '</div>';

            return stitleTipText;
        },

        //配置标题
        GoodsTitleMore: function (advertItem,iNow,num) {

            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            var titleHtml = '';
            var backColor = advertItem.backgroundColor;
            // console.log('配置标题',adItems);
            for(var i = 0; i < adItems.length; i++){
                if(adItems[i].titleType == 0){
                    titleHtml += '<div class="titleMes_set titleMesText js_moduleArea" style="width: 100%;background: #'+backColor+';" id="list'+num+'">' +
                        '<p style="color: #'+adItems[i].fontColor+'; font-size: '+(adItems[i].fontSize *2/26).toFixed(2)+'rem; text-align: '+adItems[i].titlePosition+'">'+adItems[i].moduleTitle+'</p></div>';
                }
                else if(adItems[i].titleType == 1){
                    titleHtml += '<div class="titleMes_set js_moduleArea" id="list'+num+'"><img src="'+HTTP_IMAGE_URL+adItems[i].titleImage+'" alt></div>'
                }
            }

            oSlidePageScroll.eq(iNow).find('.jsAdvert').append(titleHtml);


        },

        // 商品列表, 自定义属性 _href 按照返回的 cLink 来设置； num是该商品列表在返回的模块中的排序
        GoodsListMore: function (advertItem,iNow,num) {
            var oSlidePageScroll = $('.js_slidePageScroll');
            var adItems = JSON.parse(advertItem.items);
            var advertItem = advertItem;

            // console.log('配置专题商品',adItems);
            var goodsListHtml = '';
            var backColor = advertItem.backgroundColor;
            for(var i = 0; i < adItems.length; i++) {
                var item = adItems[i];
                var boxHtml = '<div class="goodsListGroupBox js_moduleArea" id="list'+num+'"><div class="goodsListDet js_goodsListDet" ></div></div>'; //商品列表外壳
                var listId = '#list'+ num; //保存id
                var $htmlBox = $(boxHtml);
                oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);
                var goodsList= advertItem.groupGoodsVoList;

                if(goodsList.length <= 0){
                    return;
                }
                var classes ='';
                if(item.listType == 0) {
                    classes = 'goodsListOneRow';
                }else if(item.listType == 1){
                    classes = 'goods_showChangeBox active js_goods_showTwo';
                }else if(item.listType == 2){
                    classes = 'goods_showChangeBox topicShowGoods js_goods_showOne';
                }

                var goodsHtml = '<div class="'+classes+'" style="background: #'+backColor+'"><ul class="clearfix js_goodsListOneRowUl'+num+' goodsList"></ul></div>';
                var appendUl = '.js_goodsListOneRowUl'+num;
                var $goodsHmtlBox = $(goodsHtml);
                oSlidePageScroll.eq(iNow).find(listId).append($goodsHmtlBox);

                for(var j = 0; j < goodsList.length; j++){

                    //全额保障  选择性显示哪些右上角图标
                    var firstGueeImagePath=goodsList[j].firstGueeImagePath;
                    var gueeUrlHtml = '';
                    if(firstGueeImagePath!=null && firstGueeImagePath!=""){
                        gueeUrlHtml='<img src="'+BASE_URL+'/static_v4/image/iconPic/'+firstGueeImagePath+'" alt="" class="quanpei"/>';
                    }
                    //活动标签
                    var labelHtml = '';
                    var headHotHtml = '';
                    if(goodsList[j].goodsLabel && goodsList[j].goodsLabel != ''){
                        labelHtml = '<div class="verpromotionHot"><span>'+ goodsList[j].goodsLabel +'</span><div><img src="' + BASE_URL + '/static_v4/image/iconImg/hotIcon.png" alt=""></div></div>';
                        headHotHtml = '<i class="promotionHotIcon">'+ goodsList[j].goodsLabel +'</i>'
                    }

                    //多活动标签
                    var goodsLabelHtml = '';
                    if(goodsList[j].label && goodsList[j].label != ''){
                        var eachLabelHtml = '';
                        for(var i=0;i<goodsList[j].labels.length;i++){
                            eachLabelHtml += '<i>'+goodsList[j].labels[i]+'</i>'
                        }
                        goodsLabelHtml += '<p class="promotionSale">'+
                            eachLabelHtml+
                            '</p>';
                    }

                    //是否是团购
                    var tuangouPriceHtml = '';
                    if(goodsList[j].tuangou){
                        tuangouPriceHtml =  '<span class="goodsPrice">￥' + goodsList[j].tuangouPrices + '</span>';
                    }else{
                        tuangouPriceHtml = '<span class="goodsPrice">￥' + goodsList[j].salePrice + '</span>'
                    }


                    if(item.listType == 0){
                        goodsListHtml += '<li class="bigGoodsListOne">' +
                            '                  <a class="" _href="' + goodsList[j].goodsSn + '">' +
                            '                        <figure>' +
                            '                             <img class="js_lazyImg" data-echo="'+HTTP_IMAGE_URL + goodsList[j].goodsDefaultImage+ smallImgArg +'" src="'+BASE_URL+'/static_v4/image/loadImg.jpg" alt>' +
                            gueeUrlHtml+
                            labelHtml+
                            '            </figure>' +
                            '                         <aside class="">' +
                            '                              <h4>'+headHotHtml+goodsList[j].goodsName+'</h4>' +
                            '                              <div class="goodsPriceBox HBox BoxCenter">' +
                            '                                   <p class="salesPriceBox">' +
                            tuangouPriceHtml+
                            '                                   </p>' +
                            '                                   <p class="Bflex1 goodsSalePoint"><span>'+goodsList[j].productName+'</span></p>'+
                            '                               </div>' +
                            '                         </aside>' +
                            '                   </a>' +
                            '              </li>';

                    }
                    else if(item.listType == 1){

                        goodsListHtml +=
                            '<li class="VBox">'+
                            '    <a class="BoxSelf Bflex1" _href="'+goodsList[j].goodsSn+'">'+
                            '        <figure>'+
                            '            <img class="js_lazyImg" data-echo="'+ HTTP_IMAGE_URL+goodsList[j].goodsDefaultImage + smallImgArg +'" src="'+BASE_URL+'/static_v4/image/loadImg.jpg">'+
                            gueeUrlHtml+
                            labelHtml+
                            '        </figure>'+
                            '        <aside class="priceArea VBox Bflex1">'+
                            '            <div class="Bflex1 priceArea_name">'+
                            '                <h4>'+ headHotHtml + goodsList[j].goodsName +'</h4>'+
                            '                <p class="smallFont_tip">'+goodsList[j].productName+'</p>'+
                            '            </div>'+
                            '            <div class="priceArea_price">'+
                            '                <p class="HBox priceAreaBox">'+
                            tuangouPriceHtml+
                            '                </p>'+
                            '            </div>'+
                            '        </aside>'+
                            '    </a>'+
                            // addCarHtml+
                            '</li>'
                    }
                    else if(item.listType == 2) {

                        goodsListHtml +=
                            '<li>'+
                            '   <a class="BoxSelf" _href="'+ goodsList[j].goodsSn + '">'+
                            '       <figure>'+
                            '           <img class="js_lazyImg " data-echo="' + HTTP_IMAGE_URL + goodsList[j].goodsDefaultImage + smallImgArg +'" src="' + BASE_URL + '/static_v4/image/loadImg.jpg" />'+
                            gueeUrlHtml+
                            labelHtml+
                            '       </figure>'+
                            '      <aside class="priceArea VBox Bflex1">'+
                            '           <div class="Bflex1 priceArea_name">'+
                            '               <h4>' + headHotHtml + goodsList[j].goodsName + '</h4>'+
                            '               <p class="smallFont_tip">' + goodsList[j].productName + '</p>'+
                            '           </div>'+
                            '           <div class="priceArea_price">'+
                            '               <p class="HBox priceAreaBox">'+
                            tuangouPriceHtml+
                            '               </p>'+
                            '           </div>'+
                            '       </aside>'+
                            '   </a>'+
                            '</li>';
                    }
                }

                $goodsHmtlBox.find(appendUl).append(goodsListHtml);
                myPub.JudgeAppHref($(appendUl).find('a'));

                // 产品懒加载  异步加载 调用这个
                lazLoading.DestroyLazLoadingImg();
                lazLoading.AddLazLoadingImg(oSlidePageScroll[0]);

                if(oSlidePageScroll.eq(iNow).scrollTop()==0){
                    setTimeout(function () {
                        oSlidePageScroll.eq(iNow).scrollTop(1)
                    },500);

                }

            }
        },

        // 配置导航栏
        GoodsNavigationMore: function (advertItem,iNow) {
            var that = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var backColor = advertItem.backgroundColor;
            var adItems = JSON.parse(advertItem.items);
            // console.log('配置导航栏',adItems);
            var goodsNavHtml = '';
            that.navNum++;
            var navIndex = that.navNum;

            for(var i = 0; i < adItems.length; i++){
                var item = adItems[i];
                var fontSize = (item.fontSize * 2 / 26).toFixed(2);

                if(item.navigationDatas && item.navigationDatas.length > 0){
                    var navData=[];
                    for(var j = 0; j < item.navigationDatas.length; j++){
                        var itemData = item.navigationDatas[j];

                        if(itemData.state==1){
                            var obj={
                                index : j,
                                name: itemData.name
                            };
                            navData.push(obj);
                        }
                    }
                    for(var o = 0; o < navData.length; o++){
                        var itemNav = navData[o];
                        var activeClass = o == 0 ? "active" : "";
                        goodsNavHtml +=
                            '<li class="goodsListNav js_goodsListNav '+ activeClass +' nav'+itemNav.index+'" style="padding: 0.77rem;float: none;line-height: 1.5;background: #'+backColor+';color: #'+item.fontColor+';font-size: '+fontSize+'rem;" data-id="nav'+itemNav.index+'" data-index="'+o+'">' +
                            '   <div>'+itemNav.name+'</div>' +
                            '</li>';
                    }
                }

                var navgiationHtml =
                    '<div class="goodsNavBox js_goodsNavBox width_100" style="padding:0 0.84rem;background: #'+backColor+';box-sizing: border-box;">' +
                    '   <div class="goodsNav js_goodsNav js_goodsTextNav js_goodsNavInside width_100 js_jrollscrollText" style="color: #'+item.fontColor+';font-size: '+fontSize+'rem;" data-index="'+navIndex+'">' +
                    '       <ul class="js_goodsNavUl HBox" style="white-space: nowrap;">'+goodsNavHtml+'</ul>' +
                    '    </div>'+
                    '   <div class="goodsNavEmpBox js_goodsNavEmpBox width_100 height_100" style="background: #'+backColor+'">' +
                    '    </div>' +
                    '</div>';

                var $htmlBox = $(navgiationHtml);

                oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);

                // height:'+navBoxH+'rem; overflow-x: auto;overflow-y: hidden;-webkit-overflow-scrolling: touch;width: 100%;
                var absoluteNavgationHtml =
                    '<div class="goodsNav js_goodsNav js_goodsTextNav  js_goodsNavOutside width_100 goodsNavBoxFixed hideGoodsNav" style="padding:0 0.84rem;background: #'+backColor+';color: #'+item.fontColor+';font-size: '+fontSize+'rem;box-sizing: border-box;" data-index="'+navIndex+'"><div class="js_jrollscrollText width_100">'+
                    '    <ul class="js_goodsNavUl HBox" style="white-space: nowrap;">'+goodsNavHtml+'</ul>' +
                    '</divcl></div>';
                $('body').append($(absoluteNavgationHtml));
                $('body').find('.goodsListNav.active:last').css({color: '#'+item.selectedColor});
                $('body').find('.js_goodsNavInside:last .goodsListNav.active').css({color: '#'+item.selectedColor});

                // 保存文字导航选中状态的样式
                that.activeStyle(item.fontColor,item.selectedColor);
            }
        },

        //配置图片导航栏
        NavigationPictureMore: function (advertItem,iNow,num) {
            var that = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var backColor = advertItem.backgroundColor;

            var adItems = JSON.parse(advertItem.items);
            // console.log('图片导航',adItems);
            var goodsNavHtml = '';
            that.navNum++;
            var navIndex = that.navNum;
            for(var i = 0; i < adItems.length; i++){
                var item = adItems[i];
                var fontSize = (item.fontSize * 2 / 26).toFixed(2);
                if(item.navigationDatas && item.navigationDatas.length > 0){
                    var navData=[];
                    for(var j = 0; j < item.navigationDatas.length; j++){
                        var itemData = item.navigationDatas[j];

                        if(itemData.state==1){
                            var obj={
                                index : j,
                                pic: itemData.pic
                            };
                            navData.push(obj);
                        }
                    }

                    for(var o = 0; o < navData.length; o++){
                        var itemNav = navData[o];
                        var activeClass = o == 0 ? "active" : "";
                        goodsNavHtml +=
                            '<li class="js_goodsListNav js_imgListNav navImg'+itemNav.index+'" style="padding: 0.77rem;width: 5.6rem;" data-id="navImg'+itemNav.index+'" data-index="'+o+'">' +
                            '    <figure style="position: relative">' +
                            '       <img src="' + HTTP_IMAGE_URL + itemNav.pic + '" alt="" data-growing-title="'+adItems[0].moduleName+i+'" data-img="'+  HTTP_IMAGE_URL + itemNav.pic +'">' +
                            '       <div class="js_mask '+activeClass+'" style="position: absolute;width: 100%;height: 100%;left: 0;top: 0;background-color: rgba(255,255,255,0.3)"></div>'+
                            '     </figure>' +
                            '</li>';
                    }
                }

                var backImgStyle = advertItem.backgroundImg ? "background: url("+HTTP_IMAGE_URL+advertItem.backgroundImg +") no-repeat; background-size: 100% 100%;" : "";
                var navgiationHtml =
                    '<div class="goodsNavBox js_goodsNavBox width_100" style="padding:0 0.84rem;background: #'+backColor+';box-sizing: border-box;">' +
                    '   <div class="goodsNav js_goodsNav js_goodsImgNav js_goodsNavInside width_100 js_jrollscrollImg" style="'+backImgStyle+'color: #'+item.fontColor+';font-size: '+fontSize+'rem;overflow-x: auto;overflow-y: hidden;-webkit-overflow-scrolling: touch;" data-index="'+navIndex+'">' +
                    '       <ul class="js_goodsNavUl HBox" style="white-space: nowrap;min-width: 100%;">'+goodsNavHtml+'</ul>' +
                    '    </div>'+
                    '   <div class="goodsNavEmpBox js_goodsNavEmpBox width_100 height_100" style="background: #'+backColor+'">' +
                    '    </div>' +
                    '</div>';

                var $htmlBox = $(navgiationHtml);

                oSlidePageScroll.eq(iNow).find('.jsAdvert').append($htmlBox);

                var absoluteNavgationHtml = '   <div class="goodsNav js_goodsNav js_goodsImgNav js_goodsNavOutside width_100 goodsNavBoxFixed hideGoodsNav" style="padding:0 0.84rem;background: #'+backColor+';'+'rem;color: #'+item.fontColor+';font-size: '+fontSize+'rem;box-sizing: border-box;" data-index="'+navIndex+'overflow-x: auto;overflow-y: hidden;-webkit-overflow-scrolling: touch;">' +
                    '<div class="js_jrollscrollImg width_100" style="'+backImgStyle+'">' +
                    '    <ul class="js_goodsNavUl HBox" style="white-space: nowrap;min-width: 100%;">'+goodsNavHtml+'</ul>' +
                    '</div></div>' ;
                $('body').append($(absoluteNavgationHtml));
                $('body').find('.js_mask.active:last').css({display: 'none'});
                $('body').find('.js_goodsNavInside:last .js_mask.active').css({display: 'none'});

            }
        },

        // 优惠券
        CouponMore:function(advertItem,iNow,num){
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var backColor = advertItem.backgroundColor;
            var adItems = JSON.parse(advertItem.items);
            var shtml = '';
            var thtml= '';
            // console.log('优惠券',advertItem);
            // 一张优惠券、两张优惠券、三张优惠券各自的样式
            if(adItems.length == 1 || adItems.length == 2){
                var couponClassName = '';
                if(adItems.length == 2){
                    couponClassName = 'twoCoupon'
                }
                for (var i=0; i<adItems.length; i++) {
                    var item = adItems[i];

                    shtml += '<li class="Bflex1 '+couponClassName+'" style="margin-bottom: 0">' +
                        '       <div data-sign="'+item.couponSign+'" data-couponId="'+item.couponId+'" class="js_couponArea" data-growing-title="'+advertItem.moduleName+i+'">' +
                        '           <img src="' + HTTP_IMAGE_URL + item.imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+i+'">' +
                        '       </div>' +
                        '     </li>';

                }
                thtml = ' <div class="Ads-bannerList Bflex1">' +
                        '     <ul class="HBox" style="height: 100%;width: 100%;">'+ shtml +'</ul>' +
                        ' </div>';
            }
            else if(adItems.length == 3){
                thtml = '           <div class="AdsImgShow1-2 HBox" style="width: 100%;">' +
                    '               <div class="AdsImg-href-left" style="margin: 0;">' +
                    '                   <ul style="margin-right: 0.19rem;height: 100%;">' +
                    '                       <li class="Bflex1" style="height: 100%;">' +
                    '                           <div data-sign="'+adItems[0].couponSign+'" data-couponId="'+adItems[0].couponId+'" class="js_couponArea"  data-growing-title="'+advertItem.moduleName+0+'" style="height: 100%;">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[0].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+0+'">' +
                    '                           </div>' +
                    '                       </li>' +
                    '                   </ul>' +
                    '                </div>' +
                    '                <div class="AdsImg-href-right VBox" style="width: 50%;margin: 0;">' +
                    '                   <ul class="VBox Bflex1" style="margin-left: 0.19rem;">' +
                    '                       <li class="Bflex1">' +
                    '                           <div data-sign="'+adItems[1].couponSign+'" data-couponId="'+adItems[1].couponId+'" class="js_couponArea"  data-growing-title="'+advertItem.moduleName+1+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[1].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+1+'">' +
                    '                           </div>' +
                    '                       </li>' +
                    '                       <li class="Bflex1">' +
                    '                           <div data-sign="'+adItems[2].couponSign+'" data-couponId="'+adItems[2].couponId+'" class="js_couponArea"  data-growing-title="'+advertItem.moduleName+2+'">' +
                    '                               <img src="' + HTTP_IMAGE_URL + adItems[2].imageUrl +'" alt=""  data-growing-title="'+advertItem.moduleName+2+'">' +
                    '                           </div>' +
                    '                       </li>' +
                    '                   </ul>' +
                    '               </div>' +
                    '           </div>' ;
            }

            var shtmlBox =
                '<section class="AdsImgShow AdsImgShow js_AdsImgShowBanner js_moduleArea" id="list'+num+'">'+
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>'+
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+backColor+'">'+
                '       <div class="AdsImgShowBox">'+
                '           <div class="AdsImgShowBanner HBox BoxCenter">' +
                                thtml+
                '           </div>'+
                '       </div>'+
                '   </div>'+
                '</section>';
            var $shtmlBox = $(shtmlBox);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $shtmlBox.addClass("AdsInterval_gray")
            }

            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($shtmlBox);
            //如果有返回首页的元素就要更改链接
            myPub.JudgeAppHref($('.js_AdsImgShowBanner').find('a'));

            shtml = null;
            shtmlBox = null;
            oSlidePageScroll = null;
            adItems = null;
        },

        // 2+4模块
        AdsTwoFour:function(advertItem,iNow,num){
            var _this = this;
            var adItems = JSON.parse(advertItem.items);
            var link0 = _this.GetAdsLink(adItems[0].linkType,adItems[0].link);
            var link1 = _this.GetAdsLink(adItems[1].linkType,adItems[1].link);
            var link2 = _this.GetAdsLink(adItems[2].linkType,adItems[2].link);
            var link3 = _this.GetAdsLink(adItems[3].linkType,adItems[3].link);
            var link4 = _this.GetAdsLink(adItems[4].linkType,adItems[4].link);
            var link5 = _this.GetAdsLink(adItems[5].linkType,adItems[5].link);

            var titleImage = HTTP_IMAGE_URL + adItems[0].titleImage;
            // console.log('2+4',advertItem);

            var advertHtml = [
                '<section class="AdsImgShow AdsImgShow AdsGroup2-4 js_moduleArea" id="list'+num+'">',
                '   <div class="ads-white-interval" style="background-color: #'+advertItem.topIntervalColor+'"></div>',
                '   <div class="AdsImgMain js_AdsImgMain" style="background-color: #'+advertItem.backgroundColor+'">',
                '	    <!-- 2+4广告  -->',
                '	    <div class="AdsImgShowBox">',
                '	    	<div class="AdsImgShow2-4 VBox">',
                '	    		<div class="AdsImg-href-top">',
                '	    			<ul class="HBox">',
                '	    				<li class="Bflex1 topImg_left"><a href="' + _this.GetAdsLink(adItems[0].linkType,adItems[0].link) + '" _href="' + link0 + '"  data-growing-title="'+advertItem.moduleName+1+'">' +
                '                           <img src="' + HTTP_IMAGE_URL + adItems[0].imageUrl + '" alt=""  data-growing-title="'+advertItem.moduleName+0+'"></a>' +
                '                       </li>',
                '	    				<li class="Bflex1 topImg_right"><a href="' + _this.GetAdsLink(adItems[1].linkType,adItems[1].link) + '" _href="' + link1 + '"  data-growing-title="'+advertItem.moduleName+1+'">' +
                '                           <img src="' + HTTP_IMAGE_URL + adItems[1].imageUrl + '" alt=""  data-growing-title="'+advertItem.moduleName+1+'"></a>' +
                '                       </li>',
                '	    			</ul>',
                '	    		</div>',
                '	    		<div class="AdsImg-href-bottom Bflex1 ">',
                '	    			<ul class="HBox">',
                '	    				<li class="Bflex1 ">',
                '	    					<div class="Bflex1"><a href="' + _this.GetAdsLink(adItems[2].linkType,adItems[2].link) + '" _href="' + link2 + '"  data-growing-title="'+advertItem.moduleName+2+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[2].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+2+'"></a></div>',
                '	    				</li>',
                '	    				<li class="Bflex1">',
                '	    					<div class="Bflex1"><a href="' + _this.GetAdsLink(adItems[3].linkType,adItems[3].link) + '" _href="' + link3 + '"  data-growing-title="'+advertItem.moduleName+3+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[3].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+3+'"></a></div>',
                '	    				</li>',
                '	    				<li class="Bflex1">',
                '	    					<div class="Bflex1"><a href="' + _this.GetAdsLink(adItems[4].linkType,adItems[4].link) + '" _href="' + link4 + '"  data-growing-title="'+advertItem.moduleName+4+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[4].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+4+'"></a></div>',
                '	    				</li>',
                '	    				<li class="Bflex1">',
                '	    					<div class="Bflex1"><a href="' + _this.GetAdsLink(adItems[5].linkType,adItems[5].link) + '" _href="' + link5 + '" data-growing-title="'+advertItem.moduleName+5+'">' +
                '                               <img src="' + HTTP_IMAGE_URL + adItems[5].imageUrl + '" alt="" data-growing-title="'+advertItem.moduleName+5+'"></a></div>',
                '	    				</li>',
                '	    			</ul>',
                '	    		</div>',
                '	    	</div>',
                '	    </div>',
                '   </div>',
                '</section>'].join("");
            var $advertHtml = $(advertHtml);
            if(advertItem.spacing != null && advertItem.spacing == 1){
                $advertHtml.addClass("AdsInterval_gray")
            }
            var oSlidePageScroll = $('.js_slidePageScroll');
            oSlidePageScroll.eq(iNow).find('.jsAdvert').append($advertHtml);
            myPub.JudgeAppHref($('.AdsGroup1-4').find('a'));
            adItems = null;
            advertHtml = null;
        },

        //导航的点击
        goodsNavTapFn: function (iNow,navActiveArr) {
            var _this = this;
            var oScrollPage = $('.js_slidePageScroll');
            var scrollTopNum =0;
            var styleArr = [];
            if(navActiveArr && navActiveArr.length>0){
                styleArr = navActiveArr.concat(navActiveArr)
            }
            $('.js_goodsNav').on('click',function (e) {
                var _tag = e.target;
                var $target;
                _tag.nodeName.toLowerCase() == 'li' ? $target = $(_tag) : $target = $(_tag).parents('li');
                scrollTopNum = $('.js_slidePageScroll').scrollTop();

                if($target.hasClass('js_goodsListNav')){
                    var dataId = $target.attr('data-id');
                    var idPair = dataId.indexOf('navImg')>-1?dataId.substring(6,100):dataId.substring(3,100);
                    var targetId = '#list'+idPair;
                    var dataIndex = $target.attr('data-index');             // 当前导航中li的下标
                    var index = $target.parents('.js_goodsNav').attr('data-index')-1;
                    var navH = $('.js_goodsNavBox').eq(index).height() > 0 ? $('.js_goodsNavBox').eq(index).height() : $('.js_goodsNavOutside').eq(index).height();


                    if($(targetId).length > 0){
                        var scrollTop = $(targetId).offset().top - navH + scrollTopNum;

                        if($target.hasClass('js_imgListNav')){
                            //如果是图片的导航
                            var oTextNavDom = $('.js_goodsImgNav');        // 所有的图片导航
                            for(var j = 0; j<oTextNavDom.length;j++){
                                oTextNavDom.eq(j).find('.js_mask').removeClass('active').css({display:'block'});
                                oTextNavDom.eq(j).find('.js_mask').eq(dataIndex).addClass('active').css({display:'none'});
                            }
                            _this.oSildeImgNavJRoll.forEach(function (el) {
                                el.ScrollTo(-_this.scrollImgWidth[dataIndex],0,100)
                            })
                        }
                        else{
                            // 文字导航
                            var oTextNavDom = $('.js_goodsTextNav');        // 所有的文字导航
                            for(var i = 0; i<oTextNavDom.length;i++){
                                oTextNavDom.eq(i).find('li').removeClass('active').css({color: styleArr[i].fontColor});
                                oTextNavDom.eq(i).find('li').eq(dataIndex).addClass('active').css({color:styleArr[i].selectedColor})
                            }
                            _this.oSildeNavJRoll.forEach(function (el) {
                                el.ScrollTo(-_this.scrollTextWidth[dataIndex],0,100)
                            })
                        }
                        oScrollPage.animate({scrollTop: scrollTop},200)
                    }

                }
            })
        },

        //曝光选中状态
        activeStyle: function (fontColor,selectedColor) {
            var that = this;
            var activeStyleObj ={};
            activeStyleObj.fontColor = '#' + fontColor;
            activeStyleObj.selectedColor = '#' + selectedColor;
            that.activeStyleObj = activeStyleObj;
            that.navActiveStyArr.push(activeStyleObj);
        },

        // 设置导航栏的宽度
        setNavScrollWidth: function(obj,type){
            var _this = this;
            var oScrollBox = obj[0];
            var oScrollLi = oScrollBox.querySelectorAll('li.js_goodsListNav');
            var nBoxWidth = parseInt((oScrollBox.offsetWidth)/2);
            var time_ScrollDis = null;
            // 获取导航的宽度
            var _liWidth = oScrollLi[ oScrollLi.length - 1 ].offsetLeft - oScrollLi[0].offsetLeft + oScrollLi[ oScrollLi.length - 1 ].offsetWidth+5;  // 导航的总宽度
            for(var i = 0;i < oScrollLi.length;i++){
                var nLeft = oScrollLi[i].offsetLeft;
                var nScrollWidth = 0;
                nScrollWidth = parseInt(nLeft-nBoxWidth);
                if(type== 'text'){
                    _this.scrollTextWidth.push(nScrollWidth);
                }
                else if(type== 'img'){
                    _this.scrollImgWidth.push(nScrollWidth);
                }
            }

            clearTimeout(time_ScrollDis);
            time_ScrollDis = setTimeout(function () {
                for(var i=0;i<obj.length;i++){
                    $(obj[i]).find('.js_goodsNavUl').css({width:_liWidth});
                    if(type=='text'){
                        _this.oSildeNavJRoll.push(new myPub.ScrollBar());
                        if( _this.oSildeNavJRoll[i].obj === undefined ) {
                            _this.oSildeNavJRoll[i].AddScroll(obj[i], {
                                scrollY: false,
                                scrollX: true
                            });
                        }
                        else {
                            _this.oSildeNavJRoll[i].ReScroll();
                        }
                    }
                    else if(type=='img'){
                        _this.oSildeImgNavJRoll.push(new myPub.ScrollBar());
                        if( _this.oSildeImgNavJRoll[i].obj === undefined ) {
                            _this.oSildeImgNavJRoll[i].AddScroll(obj[i], {
                                scrollY: false,
                                scrollX: true
                            });
                        }
                        else {
                            _this.oSildeImgNavJRoll[i].ReScroll();
                        }
                    }

                }
            }, 200)
        },

        // 点击优惠券领取
        getCouponEvevt:function(){
            var _this = this;
            $('.js_couponArea').on('click',function () {
                var couponSign = $(this).attr('data-sign');
                _this.getCoupon(couponSign)

            })
        },
        //   保存导航选中与不选中的状态
        navActiveStyArr: [],

        //    保存多少个导航
        navNum: 0

    };

    exports.adsHtml = adsHtml;

    var adsAjax = {
        loadAdsCount: 0,                // 加载计数
        lockScroll: function () {
            var _this = this;
            _this.loadAdsCount ++;
        },

        unlockScroll: function () {
            var _this = this;
            _this.loadAdsCount --;
        },

        // 设置广告数据
        AdsAjaxData: function (index, categoryNames, fn) {
            var _this = this;
            var advertUrl = BASE_URL +  "/m/a/supplierSubjectPage/1.0/getSupplierSubjectPage";
            var data={};
            // 获取页面传递过来的id
            if(typeof supplierPageId != 'undefined'){
                data = {"supplierPageId":supplierPageId};
            }

            G_JSON_GET(advertUrl,data,function (data) {
                var _data = data.data;
                var _ret = data.ret;
                if(_ret.code=='0'){
                    if(!_data || _data.pageModuleList.length <= 0){
                        return;
                    }
                    for (var idx = 0; idx < _data.pageModuleList.length; idx ++ ){

                        var advertItem = _data.pageModuleList[idx];
                        // console.log(advertItem.moduleType)
                        switch (advertItem.moduleType) {
                            case "NAVIGATION" :
                                // 一行n个
                                adsHtml.AdsHorizontal(advertItem, index, idx);
                                break;
                            case "NAVIGATION_MIN" :
                                // 一行n个小可以滚动 //
                                adsHtml.AdsHorizontalMin(advertItem, index, idx);
                                break;
                            case "SHOPWINDOW" :
                                // 1+2 商品模块
                                adsHtml.AdsGroup3(advertItem, index, idx);
                                break;
                            case "DOUBLEGOODS" :
                                // 1+1 商品模块
                                adsHtml.AdsGroup2(advertItem, index, idx);
                                break;
                            case "GOODSSCROLL" :
                                // 滚动商品 //
                                adsHtml.GoodsHScroll(advertItem, index, idx);
                                break;
                            case "SINGLEGOODS" :
                                // 一行一个商品
                                adsHtml.AdsBanner(advertItem, index, idx);
                                break;
                            case "GOODSGROUP" :
                                // 1+ 商品  //
                                adsHtml.AdsAndScroll(advertItem, index, idx);
                                break;
                            case "HEADLINE" :
                                ////////
                                adsHtml.AdsHeadline(advertItem, index, idx);
                                break;
                            case "ONEFOURADVERT" :
                                // 1+4 商品模块
                                adsHtml.AdsOneFour(advertItem, index, idx);
                                break;
                            case "BANNER_TYPE_1" :
                                ////////
                                adsHtml.AdsGoodsBanner(advertItem, index, idx);
                                break;
                            case "BANNER_TYPE_2" :
                                // 轮播图片模块
                                adsHtml.AdsPicBanner(advertItem, index, idx);
                                break;
                            case "TUANGOU" :
                                ///////
                                adsHtml.GoodsHScrollMore(advertItem, index, idx);
                                break;
                            case "TITLE" :
                                // 标题
                                adsHtml.GoodsTitleMore(advertItem, index, idx);
                                break;
                            case "GOODSLIST" :
                                // 商品
                                adsHtml.GoodsListMore(advertItem, index, idx, idx);
                                break;
                            case "SUPPLIER_NAVIGATION_POSITION" :
                                // 文字导航 //
                                adsHtml.GoodsNavigationMore(advertItem, index, idx);
                                break;
                            case "SUPPLIER_NAVIGATION_PICTURE" :
                                // 图片导航
                                adsHtml.NavigationPictureMore(advertItem, index, idx);
                                break;
                            case "COUPON" :
                                // 优惠券
                                adsHtml.CouponMore(advertItem, index, idx);
                                break;
                            case "TWOFOURADVERT" :
                                // 2+4模块
                                adsHtml.AdsTwoFour(advertItem, index, idx);
                                break;
                            // case "BANNER_TYPE_2" :
                            //     adsHtml.AdsHorizontalScroll(advertItem, index);
                            //     break;
                            default:
                                console.error("暂不支持的广告类型 " + advertItem.moduleType);
                                break;

                        }
                    }
                    if(fn)fn();
                }

                // 设置文字导航栏的宽的 文字导航滚动
                if($('.js_jrollscrollText') && $('.js_jrollscrollText').length>0){
                    adsHtml.setNavScrollWidth($('.js_jrollscrollText'),'text');
                }

                // 设置图片导航栏的宽的 图片导航滚动
                if($('.js_jrollscrollImg') && $('.js_jrollscrollImg').length>0){
                    adsHtml.setNavScrollWidth($('.js_jrollscrollImg'), 'img');
                }

                // 点击导航滚动
                adsHtml.goodsNavTapFn(0,adsHtml.navActiveStyArr);

                // 点击获取优惠券
                adsHtml.getCouponEvevt();
            }, function () {
                // start
                _this.lockScroll();
            }, function () {
                // end
                _this.unlockScroll();
            });
        }
    };

    exports.adsAjax = adsAjax;

});